<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改分类规格</title>
    <link rel="stylesheet"  type="text/css"  href="/lib/bootstrap/css/bootstrap.min.css">

    <link rel="stylesheet" href="/css/custom.css">
    <link rel="stylesheet" href="/css/iosOverlay.css">
    <link rel="stylesheet" href="/css/prettify.css">
    <script src="/lib/plug/modernizr-2.0.6.min.js"></script>
    <link rel="stylesheet" href="/css/style.css">
    <link rel="stylesheet"   href="/css/add.css">
</head>
<body>
    <div class="panel panel-default">
        <div class="panel-heading">修改分类规格</div>
        <div class="panel-body">
            <form class="form-horizontal" action="{:url('admin/category/specSave')}" method="post">
                <div class="form-group">
                    <label  class="col-sm-3 col-sm-offset-1 control-label">请选择一级分类：</label>
                    <div class="col-sm-8">
                        <div class="row">
                            <div class="col-sm-3 dropdown">
                                <select class="form-control"  id="first">
                                    <option value="">请选择一级分类</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 col-sm-offset-1 control-label">请选择则二级分类：</label>
                    <div class="col-sm-8">
                        <div class="row">
                            <div class="col-sm-3 dropdown">
                                <select class="form-control" id="section">
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 col-sm-offset-1 control-label">请选择三级分类：</label>
                    <div class="col-sm-8">
                        <div class="row">
                            <div class="col-sm-3 dropdown">
                                <select class="form-control" id="three">
                                </select>
                                <input type="text" name="categroy_id" hidden id="threeid">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 col-sm-offset-1 control-label">请选择规格级别：</label>
                    <div class="col-sm-8">
                        <div class="row">
                            <div class="col-sm-3 dropdown">
                                <select  class="form-control" id="type"  >
                                    <option name="spec_staff"  value="" >请选择规格级别</option>
                                    <option name="spec_staff"  value="0" >一级规格</option>
                                    <option name="spec_staff"  value="1" >二级规格</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 col-sm-offset-1 control-label">规格名称：</label>
                    <div class="col-sm-8">
                        <div class="row">
                            <div class="col-sm-3 ">
                                <input type="text" class="form-control" id="updatetypetext" name="spec_name">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 col-sm-offset-1 control-label"></label>
                    <div class="col-sm-8">
                        <div class="row">
                            <div class="col-sm-3 ">
                               <button type="button" id="bok" class="btn btn-info">确定修改</button>
                                <button type="reset" name="reset" style="display: none"></button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
</div>
<script src="/lib/jquery/jquery.min.js"></script>
<script src="/lib/bootstrap/js/bootstrap.min.js"></script>
<script src="/js/iosOverlay.js"></script>
<script src="/lib/plug/spin.min.js"></script>
<script src="/lib/plug/prettify.js"></script>
<script>
        /*请求分类start*/
        $.ajax({
            url:"{:url('admin/goods/getGoodsCate')}",
            data:{"type":"", "categroy":""},
            type:"post",
            dataType:"json",
            success:function (val) {
                var str=`<option value="" id="sectionclass">请选择一级分类</option>`;
                val=JSON.parse(val);

                for(var i=0;i<val.length;i++){
                    var cur=val[i];
                    str+=`<option name="${cur.id}"  value="${cur.categroy_name}">${cur.categroy_name}</option>`;
                }
                $("#first").html("");
                $("#first").html(str);
            }
        });
        $("#first").change(getsection);
        $("#section").change(getthree);
        function getsection() {
            var selectoption= $("#first option:selected");
            var id=selectoption.attr("name");
            $.ajax({
                url:"{:url('admin/goods/getGoodsCate')}",
                data:{"type":1, "categroy":id},
                type:"post",
                dataType:"json",
                async:false,
                success:function (val) {
                    var str=`<option value="" id="sectionclass">请选择二级分类</option>`;
                    val=JSON.parse(val);
                    for(var i=0;i<val.length;i++){
                        var cur=val[i];
                        str+=`<option name="${cur.id}"  value="${cur.categroy_name}">${cur.categroy_name}</option>`;
                    }
                    $("#section").html("");
                    $("#section").html(str);
                }
            })
        }
        function getthree() {
            var selectoption= $("#section option:selected");
            var id=selectoption.attr("name");
            $.ajax({
                url:"{:url('admin/goods/getGoodsCate')}",
                data:{"type":2, "categroy":id},
                type:"post",
                dataType:"json",
                async:false,
                success:function (val) {
                    var str=`<option value="" id="threeclass">请选择三级分类</option>`;
                    val=JSON.parse(val);
                    for(var i=0;i<val.length;i++){
                        var cur=val[i];
                        str+=`<option name="${cur.id}"  value="${cur.categroy_name}">${cur.categroy_name}</option>`;
                    }
                    $("#three").html("");
                    $("#three").html(str);
                }
            })
        }
        $("#three").change(function () {
            var $threeoption=$("#three option:selected");
            var id=$threeoption.attr("name");
            $("#threeid").val(id);
        });
        /*请求分类end*/
        /*请求分类规格*/
        $("#type").change(function () {
            var threeid= $("#threeid").val();
            var spec_staff=$("#type option:selected").val();
            $("#updatetypetext").val("");
            $.ajax({
                url:"{:url('admin/category/specUpdated')}",
                type:"post",
                data:{"categroy_id":threeid,"spec_staff":spec_staff},
                dataType:"json",
                async:false,
                success:function (val) {
                    val=eval(val);
                    if(val){
                            var curvalue=val.spec_name;
                            $("#updatetypetext").val(curvalue);
                    }else{
                        iosOverlay({
                            text: "请先添加规格",
                            duration: 2e3,
                            icon: "../../images/cross.png"
                        });
                    }
                }
            })
        });
        /*修改分类规格按钮*/
        $("#bok").click(function () {
            var threeid= $("#threeid").val();
            var spec_staff=$("#type option:selected").val();
            var spec_name=$("#updatetypetext").val();
                if(spec_name){
                    $.ajax({
                        url:"{:url('admin/category/specUpdateShow')}",
                        type:"post",
                        data:{"spec_staff":spec_staff,"categroy_id":threeid,"spec_name":spec_name},
                        dataType:"json",
                        success:function (val) {
                            if(val.code==100){
                                iosOverlay({
                                    text: "修改失败，请重试！",
                                    duration: 2e3,
                                    icon: "../../images/cross.png"
                                });
                            }else if(val.code==200){
                                iosOverlay({
                                    text: "修改成功！",
                                    duration: 2e3,
                                    icon: "../../images/check.png"
                                });
                                setTimeout(function () {
                                    window.location.reload()
                                },1000)

                            }else if(val.code==300){
                                iosOverlay({
                                    text:"规格重复了",
                                    duration: 2e3,
                                    icon: "../../images/cross.png"
                                });
                            }

                        }
                    })
                }else {
                    iosOverlay({
                        text: "请先添加规格",
                        duration: 2e3,
                        icon: "../../images/cross.png"
                    });
                }

            }
        )
    </script>
</body>
</html>